package com.jy.fxf_phone.view;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.SeekBar;

import com.jy.fxf_phone.R;

/**
 * A simple {@link Fragment} subclass.
 */
public class MusicFragment extends Fragment implements View.OnTouchListener, View.OnClickListener {
    SeekBar sbVolume;
    ImageButton ibPre, ibPlay, ibNext;
    boolean isPlaying = false;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_music, container, false);
        initViews(view);
        return view;
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ibPlay:
                if (!isPlaying) {
                    ibPlay.setSelected(true);
                    isPlaying = true;
                } else if (isPlaying) {
                    ibPlay.setSelected(false);
                    isPlaying = false;
                }
                break;
            case R.id.ibNext:
                break;
            case R.id.ibPre:
                break;
        }
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        sbVolume.getParent().requestDisallowInterceptTouchEvent(true);
        return false;
    }

    private void initViews(View view) {
        sbVolume = (SeekBar) view.findViewById(R.id.sbVolume);
        ibPlay = (ImageButton) view.findViewById(R.id.ibPlay);
        ibPre = (ImageButton) view.findViewById(R.id.ibPre);
        ibNext = (ImageButton) view.findViewById(R.id.ibNext);

        ibPlay.setOnClickListener(this);
        ibPre.setOnClickListener(this);
        ibNext.setOnClickListener(this);
        sbVolume.setOnTouchListener(this);
    }
}
